var vm = new Vue({
    el:"#app",
    data:{
        messages:''
    },
    methods:{
        getRoleList:function () {
            let roleName = $("input[name='roleName']").val();
            axios({
                method:'post',
                url:'/role/queryRolesByCondition',
                params:{"roleName":roleName}
            }).then(function(result){
                vm.messages=result.data;
            }).catch(function (err) {
                console.log(err);
            })
        }
    },
    //页面加载完自动执行
    mounted(){
        this.getRoleList();
    }
})

function toRoleInfo(t){
    let roleName = $(t).parent().siblings().eq(0).html();
    location.href = "../../../../templates/sysManage/roleManage/roleInfo.html?roleName=" + roleName;
}

function toUpdate(t){
    let roleName = $(t).parent().siblings().eq(0).html();
    location.href = "../../../../templates/sysManage/roleManage/roleUpdate.html?roleName=" + roleName;
}

function deleteRole(t){
    let roleName = $(t).parent().siblings().eq(0).html();
    let flag = confirm('确认删除该角色么？');
    if (flag){
        $.ajax({
            url:"/role/deleteRole",
            type:"post",
            data:{"roleName":roleName},
            dataType:"json",
            success:function (result){
                if (result === true){
                    alert("删除成功");
                    location.href = "../../../../templates/sysManage/roleManage/roleList.html";
                }else {
                    alert("删除失败,当前角色已被引用");
                }
            }
        })
    }
}

function toRoleAdd(){
    location.href = "../../../../templates/sysManage/roleManage/roleAdd.html";
}
